const Cart = require("../model/cart.model");
const Goods = require("../model/goods.model");
class cartService {
  async addGoods(id, body) {
    console.log(id, body, "@@!!");
    let res = await Cart.create({
      user_id: id,
      goods_id: body,
    });
    return res;
  }
  async findAll(page, pagesize) {
    let { rows, count } = await Cart.findAndCountAll({
      attributes: ["id", "number"],
      offset: (page - 1) * pagesize,
      limit: +pagesize,
      include: {
        model: Goods,
        as: "goods_info",
        attributes: [
          "id",
          "goods_name",
          "goods_num",
          "goods_price",
          "goods_img",
        ],
      },
    });
    console.log(rows, count, "rse");
    return {
      page,
      pagesize,
      total: count,
      list: rows,
    };
  }
}

module.exports = new cartService();
